<?php
declare(strict_types=1);
/**
 * @project: 兔兔找图微信小程序
 * @author: kert
 * @date: 2023/5/16
 * @link: http://www.tiku-cloud.com/
 * @site: 微信搜索-兔兔找图
 */

namespace App\Http\Controllers\Ai;

use App\Exceptions\ScoreException;
use App\Http\Controllers\Controller;
use App\Http\Requests\BaiduAiRecognitionValidate;
use App\Http\Requests\BaiduImageProcessValidate;
use App\Library\Response;
use App\Logic\User\Service\AiHistoryService;
use Illuminate\Http\JsonResponse;
use RedisException;

class BaiduController extends Controller
{
    /**
     * 百度转动漫人像生成
     * @param BaiduImageProcessValidate $validate
     * @return JsonResponse
     */
    public function imageProcess(BaiduImageProcessValidate $validate): JsonResponse
    {
        $create = (new AiHistoryService())->serviceCreate(request()->all());
        if ($create["code"] == 0) {
            return Response::success($create);
        }
        return Response::error($create);
    }

    /**
     * 百度ai识别
     * @param BaiduAiRecognitionValidate $validate
     * @return JsonResponse
     * @throws RedisException
     * @throws ScoreException
     */
    public function recognition(BaiduAiRecognitionValidate $validate): JsonResponse
    {
        return Response::success((new AiHistoryService())->serviceRecognition(request()->all()));
    }
}
